'''
Author: LHY 2601958675@qq.com
Date: 2023-05-10 16:48:56
LastEditors: LHY
LastEditTime: 2023-05-11 15:54:30
Description: 
'''

import requests
import os

if not os.path.exists(f'{os.path.abspath(os.path.dirname(__file__))}/保存图片'):  #判断在当前目录有没有存在
    os.makedirs(f'{os.path.abspath(os.path.dirname(__file__))}/保存图片') #没有则创建
print("os.getcwd()") #获取终端目录
print(os.path.dirname(__file__))  #获取文件目录
print(os.path.abspath(os.path.dirname(__file__))) #获取文件目录
print("os.path.abspath(os.path.dirname(os.getcwd()))")
print(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) #获取上一级陌路
print(os.path.abspath(os.path.join(os.path.dirname(__file__),"../.."))) #上上级目录


url='https://img0.baidu.com/it/u=726620871,4203188840&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800'  #链接地址

response=requests.get(url)  #请求
resp=response.content  #获取流
#保存操作
with open(f'{os.path.abspath(os.path.dirname(__file__))}/保存图片/图片1.jpg','wb') as f:
    f.write(resp)